package cn.bob.config;

import cn.bob.filter.springcloudGatewayFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author bob
 * @data 2022/11/13-16:13
 */
@Configuration
public class FilterConfiguration {
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder){
        return builder.routes().route(r -> r.path("/bob/pay/**")
                //去掉2个前缀
                .filters(f -> f.stripPrefix(2)
                        .filter(new springcloudGatewayFilter())
                        .addResponseHeader("X-Response-test", "test"))
                .uri("lb://pay-server")
                .order(0)
                .id("test-RequestTimeFilter")
        ).build();
    }
}
